package com.salton123.hello.cpp

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.salton123.core.HelloCpp
import com.salton123.hello.cpp.databinding.ActivityMainBinding

class MainActivity : AppCompatActivity() {

    private lateinit var binding: ActivityMainBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(binding.root)
        binding.sampleText.setOnClickListener {
            val filePointer = HelloCpp.createFile("$externalCacheDir/hellocpp.txt")
            println("get file pointer:$filePointer")
            val filePath = "$externalCacheDir/helloKmmap.txt"
            val pointer = HelloCpp.init(filePath, 16 * 1024)
            val ret = HelloCpp.write(pointer, "hello kmmap")
            if (ret == 0) {
                Toast.makeText(applicationContext, "写入成功", Toast.LENGTH_SHORT).show()
            } else {
                Toast.makeText(applicationContext, "写入失败", Toast.LENGTH_SHORT).show()
            }
        }
    }
}